package com.yonyou.cms.epc.controller.graphic;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yonyou.cms.epc.client.dto.graphic.GradeInfoDTO;
import com.yonyou.cms.epc.client.entity.graphic.GradeInfoPO;
import com.yonyou.cms.epc.client.entity.graphic.GraphicAssemblyInfoPO;
import com.yonyou.cms.epc.client.entity.graphic.GraphicInfoPO;
import com.yonyou.cms.epc.client.feign.WmsServiceFeign;
import com.yonyou.cms.epc.service.graphic.GradeInfoService;
import com.yonyou.cyx.framework.controller.base.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author jxy
 * @since 2022-06-08
 */
@RestController
@RequestMapping("/grade/gradeInfo")
public class GradeInfoController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(GradeInfoController.class);

    @Autowired
    public GradeInfoService gradeInfoService;
    @Autowired
    public WmsServiceFeign wmsServiceFeign;


    /**
     * 分页查询数据
     *
     * @param queryCondition 查询条件
     * @return com.baomidou.mybatisplus.core.metadata.IPage 分页对象
     * @author jxy
     * @since 2022-06-08
     */
    @ResponseBody
    @GetMapping
    @SuppressWarnings("unchecked")
    public IPage<Map<String, Object>> getList(@RequestParam Map<String, Object> queryCondition, @RequestParam
            ("currentPage") int currentPage, @RequestParam("pageSize") int pageSize) {
        Page<Map<String, Object>> page = new Page(currentPage, pageSize);
        return gradeInfoService.selectPageBysql(page, queryCondition);
    }

    /**
     * 进行数据修改
     *
     * @param id 数据主键ID
     * @return Map<String, Object> 数据对应的map 结构
     * @author jxy
     * @since 2022-06-08
     */
    @ResponseBody
    @GetMapping(value = "/{id}")
    @SuppressWarnings("unchecked")
    public Map<String, Object> getById(@PathVariable("id") Integer id) {
        return gradeInfoService.getById(id);
    }

    /**
     * 进行数据新增
     *
     * @param gradeInfoDTO 需要保存的DTO
     * @return Map<String, Object> 返回的数据map
     * @author jxy
     * @since 2022-06-08
     */
    @ResponseBody
    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    @SuppressWarnings("unchecked")
    public Map<String, Object> insert(@RequestBody GradeInfoDTO gradeInfoDTO) {
        logger.debug("gradeInfoDTO:{}", gradeInfoDTO);
        return gradeInfoService.insert(gradeInfoDTO);
    }

    /**
     * 进行数据修改
     *
     * @param id           需要修改数据的ID
     * @param gradeInfoDTO 需要保存的DTO
     * @return Map<String, Object> 返回的数据map
     * @author jxy
     * @since 2022-06-08
     */
    @ResponseBody
    @PutMapping(value = "/{id}")
    @ResponseStatus(HttpStatus.CREATED)
    @SuppressWarnings("unchecked")
    public Map<String, Object> update(@PathVariable("id") Integer id, @RequestBody GradeInfoDTO gradeInfoDTO) {
        logger.debug("gradeInfoDTO:{}", gradeInfoDTO);
        return gradeInfoService.update(id, gradeInfoDTO);
    }

    /**
     * 根据id删除对象
     *
     * @param id 需要修改数据的ID
     * @author jxy
     * @since 2022-06-08
     */
    @DeleteMapping(value = "/{id}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public boolean deleteById(@PathVariable("id") Integer id) {
        logger.debug("删除ID:{}", id);
        gradeInfoService.deleteById(id);
        return true;
    }

    /**
     * 根据IDs批量删除对象
     *
     * @param ids 需要修改数据的ID集合
     * @author jxy
     * @since 2022-06-08
     */
    @DeleteMapping(value = "/batch/{ids}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public boolean deleteByIds(@PathVariable("ids") String ids) {
        logger.debug("删除ID:{}", ids);
        gradeInfoService.deleteBatchIds(ids);
        return true;
    }


    /**
     * 查询下拉车型数据
     *
     * @return List<GraphicModelPO> list集合
     * @author jxy
     * @since 2022-06-08
     */
    @ResponseBody
    @GetMapping("/queryModel")
    public List<GraphicInfoPO> queryModel(@RequestParam Map<String, Object> params) {
        List<GraphicInfoPO> graphicModelPos = gradeInfoService.queryModel(params);
        return graphicModelPos;
    }

    /**
     * 查询下拉系统数据
     *
     * @return List<querySystem> list集合
     * @author jxy
     * @since 2022-06-08
     */
    @ResponseBody
    @GetMapping("/querySystem")
    public List<GraphicInfoPO> querySystem(@RequestParam Map<String, Object> map) {
        List<GraphicInfoPO> graphicModelPos = gradeInfoService.querySystem(map);
        return graphicModelPos;
    }
    /**
     * 查询树形控件中的数据
     * @param map
     * @return Map<String, Object> map
     * @author jxy
     * @since 2022-06-08
     */
    @ResponseBody
    @GetMapping("/queryGraphicInFo")
    public Map<String, Object> queryGraphicInFo(@RequestParam Map<String, Object> map) {
        Map<String,Object> outMap=new HashMap<>(16);
        List<GraphicInfoPO> graphicModelPos = gradeInfoService.queryGraphicInFo(map);
        List<GraphicAssemblyInfoPO> graphicAssemblyInfoPos = gradeInfoService.queryGraphicAssemblyInFo(map);
            outMap.put("system",graphicModelPos);
            outMap.put("assembly",graphicAssemblyInfoPos);
        return outMap;
    }
    /**
     * 查询总成或备件信息
     * @param graphicAssemblyInfoPo
     * @return List<GraphicAssemblyInfoPO>
     * @author jxy
     * @since 2022-06-08
     */
    @ResponseBody
    @GetMapping("/queryParts")
    public List<GraphicAssemblyInfoPO> queryParts(GraphicAssemblyInfoPO graphicAssemblyInfoPo) {
        List<GraphicAssemblyInfoPO> graphicAssemblyInfoPos = gradeInfoService.queryParts(graphicAssemblyInfoPo);
        return graphicAssemblyInfoPos;
    }
    /**
     * 增加和修改热点
     * @param assemblyId,list
     * @return boolean
     * @author jxy
     * @since 2022-06-08
     */
    @ResponseBody
    @PutMapping("/insertAndUpdate/{assemblyId}")
    public boolean insertAndUpdate(@PathVariable("assemblyId") Integer assemblyId,@RequestBody List<GradeInfoPO> list) {
        return gradeInfoService.insertAndUpdate(assemblyId,list);
    }
    /**
     * 查询热点
     * @param map
     * @return List<Map<String, Object>>
     * @author jxy
     * @since 2022-06-08
     */
    @ResponseBody
    @GetMapping("/queryGradeInFo")
    public List<Map<String, Object>>  queryGradeInFo(@RequestParam Map<String, Object> map) {
        List<Map<String, Object>> maps = gradeInfoService.selectListBySql(map);
        return maps;
    }
    /**
     * 查询编辑页面配件信息
     * @param graphicCode
     * @return List<GraphicAssemblyInfoPO>
     * @author jxy
     * @since 2022-06-08
     */
    @ResponseBody
    @GetMapping("/queryPartsInFo/{graphicCode}/{graphicId}")
    public List<GraphicAssemblyInfoPO> queryPartsInFo(@PathVariable("graphicCode")String graphicCode,@PathVariable("graphicId")String graphicId) {
        return gradeInfoService.queryPartsInFo(graphicCode,graphicId);
    }

    /**
     * 查询总成或配件图片
     * @param map
     * @return List<Map<String, Object>> getfilelist
     * @author jxy
     * @since 2022-06-08
     */
    @ResponseBody
    @GetMapping("/getfilelist")
    public List<Map<String, Object>> getfilelist(@RequestParam Map<String, Object> map) {
        List<Map<String, Object>> getfilelist = gradeInfoService.getfilelist(map);
        return getfilelist;
    }

    /**
     * 查询配件替换件信息
     *
     * @author chengbufang
     * @since 2022-04-09
     */
    @ResponseBody
    @GetMapping(value = "/getSubPartList")
    public List<Map<String, Object>> getSubPartList(@RequestParam Map<String, Object> queryCondition) {
        return gradeInfoService.getSubPartList(queryCondition);
    }

}